package com.spzx.product.controller;

import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.ProductSpec;
import com.spzx.product.service.IProductSpecService;
import io.swagger.v3.oas.annotations.Operation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.spzx.common.core.web.controller.BaseController;

import java.util.List;

/**
 * <p>
 * 商品规格 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-02-19
 */
@RestController
@RequestMapping("/productSpec")
public class ProductSpecController extends BaseController {

    @Autowired
    private IProductSpecService productSpecService;


    /**
     * 分页查询商品销售规格列表
     * @return
     */
    @Operation(summary = "分页查询商品销售规格列表")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<ProductSpec> list = productSpecService.selectProdctSpecList();
        return getDataTable(list);
    }

    /**
     * 保存商品规格配置
     * @param productSpec
     * @return
     */
    @Operation(summary = "保存商品规格配置")
    @PostMapping
    public AjaxResult add(@RequestBody ProductSpec productSpec) {
        productSpec.setCreateBy(SecurityUtils.getUsername());
        return toAjax( productSpecService.save(productSpec));
    }


    /**
     * 批量删除商品规格配置
     * @param ids
     * @return
     */
    @Operation(summary = "批量删除商品规格配置")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@RequestBody List<Long> ids) {
        return toAjax( productSpecService.removeBatchByIds(ids));
    }



    @Operation(summary = "根据三级分类ID查询包含商品规格配置")
    @GetMapping("/productSpecList/{categoryId}")
    public AjaxResult productSpecList(@PathVariable Long categoryId) {
        List<ProductSpec> list = productSpecService.selectProductSpecListByCategoryId(categoryId);
        return AjaxResult.success(list);
    }
}
